<?php

namespace App\Repositories;

use App\Exceptions\BasicException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class ReportRepository {

    /**
     * 删除
     */
    public function delUserReport($idArr = []) {
        $res = app('model_user_report')->whereIn("id", $idArr)->delete();

        if ($res) return $res;
        throw new BasicException(93044);
    }

    /**
     * 管理员后台查询配置数据
     */
    public function getUserReportQueryList(Array $params) {
        $whereArr = [];

        $whereFunc = function ($query) use ($params) {
        };

        $page = empty($params['page']) ? 1 : $params['page'];
        $perPage = empty($params['perPage']) ? 10 : $params['perPage'];

        $result = app('model_user_report')
            ->with("user_data:user_id,user_code,head_picture,nickname")
            ->with("report_user_data:user_id,user_code,head_picture,nickname")
            ->where($whereArr)->where($whereFunc)->orderBy('id','desc')->paginate($perPage, ['*'], '', $page);

        foreach ($result as $item) {
            $item->add_time = date("Y-m-d H:i:s", $item->add_time);
        }

        return $result;
    }

    /**
     * 删除
     */
    public function delRoomReport($idArr = []) {
        $res = app('model_room_report')->whereIn("id", $idArr)->delete();

        if ($res) return $res;
        throw new BasicException(93044);
    }

    /**
     * 管理员后台查询配置数据
     */
    public function getRoomReportQueryList(Array $params) {
        $whereArr = [];

        $whereFunc = function ($query) use ($params) {
        };

        $page = empty($params['page']) ? 1 : $params['page'];
        $perPage = empty($params['perPage']) ? 10 : $params['perPage'];

        $result = app('model_room_report')
            ->with("user:user_id,mobile,user_no")
            ->with("room:id,room_id,room_name")
            ->where($whereArr)->where($whereFunc)->orderBy('id','desc')->paginate($perPage, ['*'], '', $page);

        foreach ($result as $item) {
            $item->add_time = date("Y-m-d H:i:s", $item->add_time);
        }

        return $result;
    }

}